package com.mail.run;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.mail.service.IEmailInfoService;


public class AddEmailInfo {
    private static ApplicationContext ctx = null;
    private static String dataFilePath = "//tsclient/C/Users/heem/study/zz (HEEL-PC)/emailData2.sql";
    private static IEmailInfoService emailInfoService;
    public static void main(String[] args) {
        ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        emailInfoService = ctx.getBean(IEmailInfoService.class);
        saveDb();
    }

    public static void saveDb() {
        File file = new File(dataFilePath);
        try {
            String line = "";
            if (file != null) {
                BufferedReader reader = new BufferedReader(new FileReader(file));
                while ((line = reader.readLine()) != null) {
                    String[] emailParam = line.split(" # ");
                    if (emailParam.length > 0) {
                        emailInfoService.save(emailParam);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
